package com.mtao.controller;

import com.mtao.dto.DashscopeDto;
import com.mtao.FileUploadService;
import com.mtao.exception.BadRequestException;
import com.mtao.utils.ResultUtil;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;


@RestController
public class FileUploadController extends ResultUtil {

    @Resource
    private FileUploadService fileUploadService;
    @PostMapping("/upload")
    public ResponseEntity<Object> uploadOss(MultipartFile file){
        try{
            String upload = fileUploadService.upload(file);
            return  success("上传成功",upload);
        }catch (BadRequestException e){
            e.printStackTrace();
            return fail(e.getMsg());
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }

    /**
     * Ai 图像生成
     * @param dashscopeDto
     * @return
     */
    @PostMapping("/create/img")
    public ResponseEntity<Object> createImg(@RequestBody DashscopeDto dashscopeDto){
        try{
            dashscopeDto.setN(1);
            dashscopeDto.setSize("1024*1024");
            dashscopeDto.setPrompt("雄鹰自由自在的在蓝天白云下飞翔");
            String upload = fileUploadService.createImg(dashscopeDto);
            return  success("操作成功",upload);
        }catch (BadRequestException e){
            e.printStackTrace();
            return fail(e.getMsg());
        } catch (Exception e) {
            e.printStackTrace();
            return fail(e.getMessage());
        }
    }
}
